package com.thinkfit.jy.presenter;

import com.common.lib.manager.DataManager;
import com.common.lib.mvp.BasePresenter;
import com.common.lib.network.HttpListener;
import com.common.lib.network.HttpMethods;
import com.common.lib.network.HttpObserver;
import com.thinkfit.jy.contract.UpdateProfileContract;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class UpdateProfilePresenter extends BasePresenter<UpdateProfileContract.View> implements UpdateProfileContract.Presenter {

    public UpdateProfilePresenter(@NotNull UpdateProfileContract.View rootView) {
        super(rootView);
    }


    @Override
    public void updateUser(String key, Object value) {
        HttpMethods.Companion.getInstance().editUser(
                DataManager.Companion.getInstance().getMyInfo().getUid(),
                key, String.valueOf(value),
                new HttpObserver(getRootView(), new HttpListener<Object>() {
                    @Override
                    public void onSuccess(@Nullable Object bean) {
                        if (getRootView() == null) {
                            return;
                        }
                        getRootView().updateUserSuccess(value);
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                    }
                }, getCompositeDisposable()));
    }
}
